Skip to content

fix(pwa): let docs navigations past the service worker - #68

Merged
ndreno merged 2 commits into
mainfrom
fix/pwa-docs-fallback
Nov 6, 2026
Merged

ndreno merged 2 commits into
mainfrom
fix/pwa-docs-fallback

Conversation

@ndreno

@ndreno ndreno commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Problem

Once a browser has opened the web app, every link to https://werb-dev.github.io/werb/docs/ shows the app instead of the documentation.

The service worker's scope is /werb/, and the docs live in /werb/docs/. Workbox answers any navigation it doesn't know with the precached index.html. The docs are copied into dist/ after the Vite build, so they're never precached and always hit that fallback.

Reproduced on the live site in Chromium:

URL No service worker After visiting the app
/werb/docs/ docs app
/werb/docs/install.html docs app
/werb/docs 301 to /werb/docs/, docs app

Fix

navigateFallbackDenylist: [^<base>docs(/|$)] in the Workbox config, so navigations under docs/ go to the network. The regex follows VITE_BASE: it is /^\/werb\/docs(\/|$)/ on Pages and /^\/docs(\/|$)/ locally.

Browsers that already have the old worker pick up the fix after accepting the next update (the "New version available" banner).

Tests

  • New test/e2e/pwa.spec.ts: drops a probe page into dist/docs/, waits for the worker to control the page, then navigates to the probe.
    • Fails on main (gets the "Werb" app shell).
    • Passes with the fix.
  • Full e2e suite: 37 passed. Lint and typecheck are clean.

The mdBook docs are deployed under /werb/docs/, inside the PWA service
worker's /werb/ scope. Workbox answers every unknown navigation with the
precached index.html, and the docs are copied into dist/ after the Vite
build so they are never precached: once a browser had opened the app,
every docs URL (README, issues, CLI help links) showed the app instead.

navigateFallbackDenylist now excludes <base>docs/ so those navigations go
to the network. Browsers with the old worker get the fix after accepting
the next update.

Tests: e2e drives the production bundle, waits for the worker to control
the page, then loads a page under docs/ (fails without the fix: the app
shell comes back).
@ndreno
ndreno merged commit 5644d62 into main Nov 6, 2026
1 check passed
@ndreno
ndreno deleted the fix/pwa-docs-fallback branch November 6, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant